<template>
  <view class="box">
    <view
      class="tou top fixed"
      :style="'padding-top:' + statusBarHeight1 + 'px'"
    >
      <image
        @click="fanhui"
        class="image1"
        src="https://pic.bangbangtongcheng.com/static/fanhui_bai.png"
      />
      店铺认证
    </view>
    <view
      class="tou top"
      :style="'padding-top:' + statusBarHeight1 + 'px'"
    ></view>
    <form>
      <view class="cu-form-group">
        <view class="title"> <span style="color: red">*</span>公司名称 </view>
        <input
          type="text"
          v-model="dprzData.storeName"
          placeholder="请填写公司名称"
        />
      </view>
      <view class="cu-form-group" style="justify-content: left">
        <view class="title"> <span style="color: red">*</span>门店类型 </view>
        <template v-if="!cxbj_jy">
          <picker
            @change="type11Chage"
            :disabled="cxbj_jy"
            :data-index="type11Index"
            range-key="valueName"
            :range="type11"
          >
            <view class="picker">{{
              type11Index > -1 ? type11[type11Index].valueName : "请选择"
            }}</view>
          </picker>
        </template>
        <view class="picker" style="flex: 1" @click="tishi" v-else>{{
          type11Index > -1 ? type11[type11Index].valueName : "请选择"
        }}</view>
      </view>
      <view class="cu-form-group">
        <view class="title"> <span style="color: red">*</span>办公区域 </view>
        <picker
          @change="dictionariesChange"
          :data-index="index"
          range-key="valueName"
          :range="dictionaries"
        >
          <view class="picker">{{
            index > -1 ? dictionaries[index].valueName : "请选择"
          }}</view>
        </picker>
      </view>
      <view class="cu-form-group">
        <view class="title"> <span style="color: red">*</span>办公地址 </view>
        <template v-if="dprzData.officeAddress">
          <input v-model="dprzData.officeAddress" />
        </template>
        <template v-else>
          <input
            v-model="dprzData.officeAddress"
            @click=""
            disabled="true"
            placeholder="请选择定位获取地址"
          />
        </template>
        <text
          class="cuIcon-locationfill text-orange"
          @click="openMap"
          style="color: #64b6a8"
        ></text>
      </view>
      <view class="cu-form-group">
        <view class="title">
          <span style="color: red">*</span>门店联系电话
        </view>
        <input
          type="number"
          v-model="dprzData.storeContactNumber"
          maxlength="11"
          placeholder="请填写门店联系方式"
        />
      </view>
      <view class="cu-form-group">
        <view class="title"> <span style="color: red">*</span>法人姓名 </view>
        <input
          type="text"
          v-model="dprzData.legalName"
          placeholder="请填写法人姓名"
        />
        <!-- <input type="text" v-if="!cxbj_jy" v-model="dprzData.legalName" placeholder="请填写法人姓名" /> -->
        <!-- <input type="text" @click="tishi" v-else v-model="dprzData.legalName" placeholder="请填写法人姓名" /> -->
      </view>
      <view class="cu-form-group">
        <view class="title">
          <span style="color: red">*</span>联系人手机号
        </view>
        <!-- <input type="text" @click="tishi" v-model="dprzData.contactPhoneNumber" placeholder="请填写联系方式" disabled /> -->
        <input
          type="text"
          v-model="dprzData.contactPhoneNumber"
          disabled
          placeholder="请填写联系方式"
        />
      </view>
      <view class="cu-form-group">
        <view class="title"> <span style="color: red">*</span>店铺介绍 </view>
      </view>
      <view class="jieshao">
        <view class="kuang">
          <view class="">
            <textarea
              v-model="dprzData.storeIntroduction"
              maxlength="500"
              auto-height
              style="min-height: 100px"
              @input="sumfountnum"
              placeholder="请详细介绍店铺"
            />
          </view>
          <view class="biaoqian"
            >{{ dprzData.storeIntroduction.length }}/500</view
          >
        </view>
      </view>
      <view class="cu-form-group">
        <view class="title">
          <span style="color: red">*</span>门店封面图片
        </view>
      </view>
      <view class="shangchuan">
        <view class="cu-form-group">
          <imageUploadCropper
            v-model="imgList"
            :lengthNum="1"
            selWidth="600rpx"
            selHeight="400rpx"
            :ratio="1.5"
          ></imageUploadCropper>
        </view>
        <view style="padding-left: 40rpx"> </view>
      </view>
      <view class="cu-form-group">
        <view class="title"> <span style="color: red">*</span>营业执照 </view>
      </view>
      <view class="shangchuan">
        <view class="cu-form-group">
          <!-- <view class="grid col-4 grid-square flex-sub">
            <view class="bg-img" v-for="(item, index) in imgList2" :key="index" @tap="ViewImage2"
              :data-url="imgList2[index]">
              <image :src="imgUrl + imgList2[index]" mode="aspectFit" />
              <view class="cu-tag bg-red" @tap.stop="DelImg2" :data-index="index" v-if="status != 0">
                <text class="cuIcon-close"></text>
              </view>
            </view>
            <view class="solids" @tap="ChooseImages(2)" v-if="imgList2.length < 1">
              <text class="cuIcon-cameraadd"></text>
            </view>
          </view> -->
          <imageUpload v-model="imgList2" :lengthNum="1"></imageUpload>
        </view>
        <view
          style="
            font-size: 24rpx;
            color: #999999;
            background-color: #fff;
            padding-left: 40rpx;
          "
          >上传要求信息清晰、最大2mb</view
        >
      </view>
      <view class="cu-form-group">
        <view class="title">
          <!-- <span style="color: red">*</span> -->
          法人身份证（人像面）
        </view>
      </view>
      <view class="sfz">
        <view class="cu-form-group">
          <view class="grid col-4 grid-square flex-sub">
            <view
              class="bg-img id_card"
              v-for="(item, index) in imgList3"
              :key="index"
              @tap="ViewImage3"
              :data-url="imgList3[index]"
            >
              <image :src="imgUrl + imgList3[index]" mode="aspectFit" />
              <view
                class="cu-tag bg-red"
                @tap.stop="DelImg3"
                :data-index="index"
                v-if="status != 0"
              >
                <text class="cuIcon-close"></text>
              </view>
            </view>
            <view
              class="solids id_card"
              @tap="ChooseImages(3)"
              v-if="imgList3.length < 1"
            >
              <img
                style="width: 100%; height: 100%"
                src="https://pic.bangbangtongcheng.com/static/sfz_f.png"
                alt
              />
            </view>
          </view>
        </view>
      </view>
      <view class="cu-form-group">
        <view class="title">
          <!-- <span style="color: red">*</span> -->
          法人身份证（国徽面）
        </view>
      </view>
      <view class="sfz">
        <view class="cu-form-group">
          <view class="grid col-4 grid-square flex-sub">
            <view
              class="bg-img id_card"
              v-for="(item, index) in imgList4"
              :key="index"
              @tap="ViewImage4"
              :data-url="imgList4[index]"
            >
              <image :src="imgUrl + imgList4[index]" mode="aspectFit" />
              <view
                class="cu-tag bg-red"
                @tap.stop="DelImg4"
                :data-index="index"
                v-if="status != 0"
              >
                <text class="cuIcon-close"></text>
              </view>
            </view>
            <view
              class="solids id_card"
              @tap="ChooseImages(4)"
              v-if="imgList4.length < 1"
            >
              <img
                style="width: 100%; height: 100%"
                src="https://pic.bangbangtongcheng.com/static/sfz_z.png"
                alt
              />
            </view>
          </view>
        </view>
      </view>
      <!-- 身份证 -->
      <view class="cu-form-group">
        <view class="title">
          <span style="color: red">*</span>个人身份证（人像面）
        </view>
      </view>
      <view class="sfz">
        <view class="cu-form-group">
          <view class="grid col-4 grid-square flex-sub">
            <view
              class="bg-img id_card"
              v-for="(item, index) in imgList9"
              :key="index"
              @tap="ViewImage9"
              :data-url="imgList9[index]"
            >
              <image :src="imgUrl + imgList9[index]" mode="aspectFit" />
              <view
                class="cu-tag bg-red"
                @tap.stop="DelImg9"
                :data-index="index"
                v-if="status != 0"
              >
                <text class="cuIcon-close"></text>
              </view>
            </view>
            <view
              class="solids id_card"
              @tap="ChooseImages(9)"
              v-if="imgList9.length < 1"
            >
              <img
                style="width: 100%; height: 100%"
                src="https://pic.bangbangtongcheng.com/static/sfzgr_f.png"
                alt
              />
            </view>
          </view>
        </view>
      </view>
      <view class="cu-form-group">
        <view class="title">
          <span style="color: red">*</span>个人身份证（国徽面）
        </view>
      </view>
      <view class="sfz">
        <view class="cu-form-group">
          <view class="grid col-4 grid-square flex-sub">
            <view
              class="bg-img id_card"
              v-for="(item, index) in imgList10"
              :key="index"
              @tap="ViewImage10"
              :data-url="imgList10[index]"
            >
              <image :src="imgUrl + imgList10[index]" mode="aspectFit" />
              <view
                class="cu-tag bg-red"
                @tap.stop="DelImg10"
                :data-index="index"
                v-if="status != 0"
              >
                <text class="cuIcon-close"></text>
              </view>
            </view>
            <view
              class="solids id_card"
              @tap="ChooseImages(10)"
              v-if="imgList10.length < 1"
            >
              <img
                style="width: 100%; height: 100%"
                src="https://pic.bangbangtongcheng.com/static/sfzgr_z.png"
                alt
              />
            </view>
          </view>
        </view>
      </view>
    </form>

    <!-- #ifdef MP-WEIXIN -->
    <cropper ref="croop" v-show="showCroop" :quality="1" resize: false
    :canScale="true" selWidth="624rpx" selHeight="416rpx" style='z-index:1000'
    @upload="myUpload" class="userHeader" />
    <!-- #endif -->
    <!-- #ifndef MP-WEIXIN-->
    <gmy-img-cropper
      ref="gmyImgCropper"
      quality="1"
      cropperType="ratio"
      :ratio="1.5"
      fileType="png"
      imgSrc=""
      style="z-index: 1000"
      @getImg="myUpload"
    >
    </gmy-img-cropper>
    <!-- #endif -->
    <view class="tijiao">
      <view class="but" v-if="status == 0">审核中，请耐心等待</view>
      <view class="but" v-if="status != 0" @click="submit">提交</view>
    </view>
    <uniBall></uniBall>
  </view>
</template>
<script>
import permision from "@/js_sdk/wa-permission/permission.js";
//#ifdef H5
import wxshare from "../../utils/index.js";
//#endif
//#ifdef MP-WEIXIN
import cropper from "../../components/lxiaoxiao-cropper/lxiaoxiao-cropper.vue";
//#endif

// #ifndef MP-WEIXIN
import gmyImgCropper from "../../components/gmy-img-cropper/gmy-img-cropper.vue";
//#endif
import imageUploadCropper from "@/components/imageUploadCropper.vue";
import imageUpload from "@/components/imageUpload.vue";
import { mapGetters } from "vuex";
export default {
  components: {
    // #ifndef MP-WEIXIN
    gmyImgCropper,
    //#endif
    //#ifdef MP-WEIXIN
    cropper,
    //#endif
    imageUploadCropper,
    imageUpload,
  },
  data() {
    return {
      type11: [
        { id: 1, valueName: "4S店" },
        { id: 2, valueName: "汽贸店" },
        { id: 3, valueName: "美容装饰" },
        { id: 4, valueName: "维修保养" },
      ],
      type11Index: -1,
      dprzData: {
        userId: "",
        id: "",
        storeName: "",
        storeType: "",
        officeArea: "",
        officeAddress: "",
        longitude: "",
        latitude: "",
        storeContactNumber: "",
        legalName: "",
        contactPhoneNumber: "",
        storeIntroduction: "",
        storeCoverImage: "",
        businessLicense: "",
        legalIdcardJust: "",
        legalIdcardBack: "",
        personalIdcardJust: "",
        personalIdcardBack: "",
      },
      image: "",
      status: "2",
      imgList: [],
      imgList2: [],
      imgList3: [],
      imgList4: [],
      // 个人身份证
      imgList9: [],
      imgList10: [],
      userInfo: uni.getStorageSync("Pduser"),
      index: -1,
      dictionaries: [],
      foutnum: 0,
      imgUrl: this.$imgSrc,
      amend: "",
      type: "",
      // 防抖
      anti_shake: false,
      // 是否重新编辑禁用
      cxbj_jy: false,
      // 小程序裁剪是否展示
      showCroop: false,
    };
  },
  computed: {
    ...mapGetters(["statusBarHeight1", "userinfo"]),
  },
  onLoad(e) {
    this.dprzData.contactPhoneNumber = this.userInfo.phone;
    if (uni.getStorageSync("locationState") == 1) {
      this.getLocation();
    }
    this.getDictionaries();
    // this.getType()
    this.init();
    /* #ifdef H5 */
    this.jinzhi();
    /* #endif */
    this.amend = e.amend;
    this.type = e.type;
  },
  methods: {
    init() {
      let that = this;
      that.imgList = [];
      that.imgList2 = [];
      that.imgList3 = [];
      that.imgList4 = [];
      that.imgList9 = [];
      that.imgList10 = [];
      this.$myRequest
        .get("/api/mobile/vehicleOwner/getPersonalDistributorById", {
          userId: that.userInfo.id,
        })
        .then((res) => {
          if (res.distributorList) {
            this.dprzData.userId = res.distributorList.userId;
            res.distributorList.auditStatus !== "2" && (this.cxbj_jy = true);
            this.dprzData.id = res.distributorList.originalId
              ? res.distributorList.originalId
              : res.distributorList.id;
            this.dprzData.storeName = res.distributorList.storeName;
            this.dprzData.storeType = res.distributorList.storeType;
            this.dprzData.officeArea = res.distributorList.officeArea;
            this.type11.forEach((i, j) => {
              if (i.id == res.distributorList.storeType) {
                this.type11Index = j;
              }
            });
            for (var i = 0; i < that.dictionaries.length; i++) {
              if (
                that.dictionaries[i].valueName == res.distributorList.officeArea
              ) {
                that.index = i;
              }
            }
            this.dprzData.officeAddress = res.distributorList.officeAddress;
            this.dprzData.longitude = res.distributorList.longitude;
            this.dprzData.latitude = res.distributorList.latitude;
            this.dprzData.storeContactNumber =
              res.distributorList.storeContactNumber;
            this.dprzData.legalName = res.distributorList.legalName;
            this.dprzData.contactPhoneNumber =
              res.distributorList.contactPhoneNumber;
            this.dprzData.storeIntroduction =
              res.distributorList.storeIntroduction;
            that.imgList.push(res.distributorList.storeCoverImage);
            that.imgList2.push(res.distributorList.businessLicense);
            that.imgList3.push(res.distributorList.legalIdcardJust);
            that.imgList4.push(res.distributorList.legalIdcardBack);
            that.imgList9.push(res.distributorList.personalIdcardJust);
            that.imgList10.push(res.distributorList.personalIdcardBack);
            this.status = res.distributorList.auditStatus;
          }
        });
    },
    RadioChange(e) {
      this.shopType = e.detail.value;
    },
    tishi() {
      uni.showToast({
        title: "当前选择无法更改！",
        duration: 2000,
        icon: "none",
      });
    },
    // 连锁店
    multipleChange(e) {
      this.multipleShop = e.detail.value;
    },
    mendian() {
      uni.navigateTo({
        url: "/pages/my/shop",
      });
    },
    sumfountnum(e) {
      this.foutnum = e.detail.value.length;
    },
    getDictionaries() {
      this.$myRequest
        .get("/mob/home/getDictionaries", {
          type: "7",
        })
        .then((res) => {
          this.dictionaries = res.list;
        });
    },
    getType() {
      let that = this;
      this.$myRequest
        .get("/api/mobile/vehicleOwner/queryDataDictionaryList", {
          type: "11",
        })
        .then((res) => {
          res.dataDictionaryList.forEach((el) => {
            el.active = false;
            if (el.type == 11) {
              that.type11.push(el);
            }
          });
        });
    },
    dictionariesChange(e) {
      this.index = e.detail.value;
      this.dprzData.officeArea = this.dictionaries[this.index].valueName;
    },
    type11Chage(e) {
      this.type11Index = e.detail.value;
      this.dprzData.storeType = this.type11[this.type11Index].id;
    },
    ViewImage(e) {
      uni.previewImage({
        urls: this.imgList,
        current: e.currentTarget.dataset.url,
      });
    },

    ViewImage2(e) {
      uni.previewImage({
        urls: this.imgList2,
        current: e.currentTarget.dataset.url,
      });
    },
    ViewImage3(e) {
      uni.previewImage({
        urls: this.imgList3,
        current: e.currentTarget.dataset.url,
      });
    },
    ViewImage4(e) {
      uni.previewImage({
        urls: this.imgList4,
        current: e.currentTarget.dataset.url,
      });
    },
    ViewImage9(e) {
      uni.previewImage({
        urls: this.imgList9,
        current: e.currentTarget.dataset.url,
      });
    },
    ViewImage10(e) {
      uni.previewImage({
        urls: this.imgList10,
        current: e.currentTarget.dataset.url,
      });
    },
    DelImg(e) {
      uni.showModal({
        title: "",
        content: "确定要删除头像？",
        cancelText: "取消",
        confirmText: "确定",
        success: (res) => {
          if (res.confirm) {
            this.imgList.splice(e.currentTarget.dataset.index, 1);
          }
        },
      });
    },
    DelImg2(e) {
      uni.showModal({
        title: "",
        content: "确定要删除营业执照？",
        cancelText: "取消",
        confirmText: "确定",
        success: (res) => {
          if (res.confirm) {
            this.imgList2.splice(e.currentTarget.dataset.index, 1);
          }
        },
      });
    },
    DelImg3(e) {
      uni.showModal({
        title: "",
        content: "确定要删除身份证人像面？",
        cancelText: "取消",
        confirmText: "确定",
        success: (res) => {
          if (res.confirm) {
            this.imgList3.splice(e.currentTarget.dataset.index, 1);
          }
        },
      });
    },
    DelImg4(e) {
      uni.showModal({
        title: "",
        content: "确定要删除身份证国徽面？",
        cancelText: "取消",
        confirmText: "确定",
        success: (res) => {
          if (res.confirm) {
            this.imgList4.splice(e.currentTarget.dataset.index, 1);
          }
        },
      });
    },
    DelImg9(e) {
      uni.showModal({
        title: "",
        content: "确定要删除个人身份证人像面？",
        cancelText: "取消",
        confirmText: "确定",
        success: (res) => {
          if (res.confirm) {
            this.imgList9.splice(e.currentTarget.dataset.index, 1);
          }
        },
      });
    },
    DelImg10(e) {
      uni.showModal({
        title: "",
        content: "确定要删除个人身份证国徽面？",
        cancelText: "取消",
        confirmText: "确定",
        success: (res) => {
          if (res.confirm) {
            this.imgList10.splice(e.currentTarget.dataset.index, 1);
          }
        },
      });
    },
    ChooseImage() {
      let _this = this;
      _this.imgList = [];
      uni.chooseImage({
        count: 1, //默认1
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        // sourceType: ["album"], //从相册选择
        sourceType: ["camera", "album"],
        success: (res) => {
          var imgFiles = res.tempFilePaths;
          const tempFiles = res.tempFiles;
          let length = "";
          // #ifdef H5
          length = tempFiles[0].name.length;
          let resType = tempFiles[0].name.substring(length - 1, length);
          // #endif
          // #ifndef H5
          length = tempFiles[0].path.length;
          let resType = tempFiles[0].path.substring(length - 1, length);
          // #endif
          if (resType != "g" && resType != "G") {
            uni.showToast({
              title: "不支持当前文件格式",
              icon: "none",
            });
            return;
          }
          if (imgFiles.length > 1) {
            uni.showToast({
              title: "图片最多不能超过1张",
              duration: 2000,
              icon: "none",
            });
            return;
          }
          var uper;
          imgFiles.forEach((el) => {
            uni.showToast({
              title: "正在上传请稍后",
              icon: "none",
              duration: 2000,
            });
            uper = uni.uploadFile({
              // 需要上传的地址
              url:
                "https://www.bangbangtongcheng.com/conven/" +
                "ht/attach/qnUpload",
              // filePath 需要上传的文件
              filePath: el,
              name: "file",
              success(res1) {
                _this.imgList.push(JSON.parse(res1.data).data[0].url);
              },
            });
          });
          // onProgressUpdate 上传对象更新的方法
          uper.onProgressUpdate(function (res) {});
        },
        fail: (fail) => {
          uni.showModal({
            title: "提示",
            content: "操作权限已被拒绝，请手动前往设置",
            confirmText: "立即设置",
            success: (res) => {
              if (res.confirm) {
                if (plus.os.name === "iOS") {
                  plus.runtime.openURL("app-settings://");
                } else {
                  var Intent = plus.android.importClass(
                    "android.content.Intent"
                  );
                  var Settings = plus.android.importClass(
                    "android.provider.Settings"
                  );
                  var Uri = plus.android.importClass("android.net.Uri");
                  var mainActivity = plus.android.runtimeMainActivity();
                  var intent = new Intent();
                  intent.setAction(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                  );
                  var uri = Uri.fromParts(
                    "package",
                    mainActivity.getPackageName(),
                    null
                  );
                  intent.setData(uri);
                  mainActivity.startActivity(intent);
                }
              }
            },
          });
        },
      });
    },
    jinzhi() {
      let _this = this;
      let param = window.location.href.split("#")[0];
      uni.request({
        method: "post",
        data: {
          url: param,
        },
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        url: "https://www.bangbangtongcheng.com/conven//mob/login/getJsTicket.do",
        success(re) {
          _this.jinzhifx(re.data);
        },
      });
    },
    jinzhifx(data) {
      wxshare.config({
        debug: false, //是否打开调试
        appId: data.appId, // 公众号的唯一标识
        timestamp: data.timestamp, // 生成签名的时间戳
        nonceStr: data.nonce, // ，生成签名的随机串
        signature: data.signature, // 签名
        jsApiList: ["hideMenuItems"],
      });
      // 禁止分享
      wxshare.hideMenuItems({
        // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
        menuList: [
          "menuItem:share:appMessage",
          "menuItem:share:timeline",
          "menuItem:share:timeline",
          "menuItem:share:qq",
          "menuItem:favorite",
          "menuItem:share:QZone",
          "menuItem:openWithSafari",
        ],
      });
    },
    // 裁剪
    otherChooseImage() {
      // #ifdef MP-WEIXIN
      this.showCroop = true;
      this.$refs.croop.fSelect();
      //  #endif
      // #ifndef MP-WEIXIN
      this.$refs.gmyImgCropper.chooseImage();
      //  #endif
    },
    myUpload(rsp) {
      let filePath = "";
      // #ifndef MP-WEIXIN
      this.userInfo.image = rsp;
      filePath = rsp;
      // #endif
      // #ifdef MP-WEIXIN
      this.userInfo.image = rsp.path;
      filePath = rsp.path;
      this.showCroop = false;
      //  #endif

      var _this = this;
      this.imgList = [];
      var uper;

      uni.showToast({
        title: "正在上传请稍后",
        icon: "none",
        duration: 2000,
      });
      uper = uni.uploadFile({
        // 需要上传的地址
        url: "https://www.bangbangtongcheng.com/conven/" + "ht/attach/qnUpload",
        // filePath 需要上传的文件
        filePath: filePath,
        name: "file",
        success(res1) {
          _this.imgList.push(JSON.parse(res1.data).data[0].url);
        },
      });

      // onProgressUpdate 上传对象更新的方法
      uper.onProgressUpdate(function (res) {});
    },
    async ChooseImages(type) {
      if (type == 0) {
        this.otherChooseImage();
      }
      if (type == 2) {
        this.ChooseImage2();
      }
      if (type == 3) {
        this.ChooseImage3();
      }
      if (type == 4) {
        this.ChooseImage4();
      }
      if (type == 9) {
        this.ChooseImage9();
      }
      if (type == 10) {
        this.ChooseImage10();
      }
    },

    ChooseImage2() {
      let _this = this;
      _this.imgList2 = [];
      uni.chooseImage({
        count: 1, //默认1
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        // sourceType: ["album"], //从相册选择
        sourceType: ["camera", "album"],
        success: (res) => {
          var imgFiles = res.tempFilePaths;
          const tempFiles = res.tempFiles;
          let length = "";
          // #ifdef H5
          length = tempFiles[0].name.length;
          let resType = tempFiles[0].name.substring(length - 1, length);
          // #endif
          // #ifndef H5
          length = tempFiles[0].path.length;
          let resType = tempFiles[0].path.substring(length - 1, length);
          // #endif
          if (resType != "g" && resType != "G") {
            uni.showToast({
              title: "不支持当前文件格式",
              icon: "none",
            });
            return;
          }
          if (imgFiles.length > 1) {
            uni.showToast({
              title: "图片最多不能超过1张",
              duration: 2000,
              icon: "none",
            });
            return;
          }
          var uper;
          imgFiles.forEach((el) => {
            uni.showToast({
              title: "正在上传请稍后",
              icon: "none",
              duration: 2000,
            });
            uper = uni.uploadFile({
              // 需要上传的地址
              url:
                "https://www.bangbangtongcheng.com/conven/" +
                "ht/attach/qnUpload",
              // filePath 需要上传的文件
              filePath: el,
              name: "file",
              success(res1) {
                _this.imgList2.push(JSON.parse(res1.data).data[0].url);
              },
            });
          });
          // onProgressUpdate 上传对象更新的方法
          uper.onProgressUpdate(function (res) {});
        },
        fail: (fail) => {
          uni.showModal({
            title: "提示",
            content: "操作权限已被拒绝，请手动前往设置",
            confirmText: "立即设置",
            success: (res) => {
              if (res.confirm) {
                if (plus.os.name === "iOS") {
                  plus.runtime.openURL("app-settings://");
                } else {
                  var Intent = plus.android.importClass(
                    "android.content.Intent"
                  );
                  var Settings = plus.android.importClass(
                    "android.provider.Settings"
                  );
                  var Uri = plus.android.importClass("android.net.Uri");
                  var mainActivity = plus.android.runtimeMainActivity();
                  var intent = new Intent();
                  intent.setAction(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                  );
                  var uri = Uri.fromParts(
                    "package",
                    mainActivity.getPackageName(),
                    null
                  );
                  intent.setData(uri);
                  mainActivity.startActivity(intent);
                }
              }
            },
          });
        },
      });
    },
    ChooseImage3() {
      let _this = this;
      _this.imgList3 = [];
      uni.chooseImage({
        count: 1, //默认1
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        // sourceType: ["album"], //从相册选择
        sourceType: ["camera", "album"],
        success: (res) => {
          var imgFiles = res.tempFilePaths;
          const tempFiles = res.tempFiles;
          let length = "";
          // #ifdef H5
          length = tempFiles[0].name.length;
          let resType = tempFiles[0].name.substring(length - 1, length);
          // #endif
          // #ifndef H5
          length = tempFiles[0].path.length;
          let resType = tempFiles[0].path.substring(length - 1, length);
          // #endif
          if (resType != "g" && resType != "G") {
            uni.showToast({
              title: "不支持当前文件格式",
              icon: "none",
            });
            return;
          }
          if (imgFiles.length > 1) {
            uni.showToast({
              title: "图片最多不能超过1张",
              duration: 2000,
              icon: "none",
            });
            return;
          }
          var uper;
          imgFiles.forEach((el) => {
            uni.showToast({
              title: "正在上传请稍后",
              icon: "none",
              duration: 2000,
            });
            uper = uni.uploadFile({
              // 需要上传的地址
              url:
                "https://www.bangbangtongcheng.com/conven/" +
                "ht/attach/qnUpload",
              // filePath 需要上传的文件
              filePath: el,
              name: "file",
              success(res1) {
                _this.imgList3.push(JSON.parse(res1.data).data[0].url);
              },
            });
          });
          // onProgressUpdate 上传对象更新的方法
          uper.onProgressUpdate(function (res) {});
        },
        fail: (fail) => {
          uni.showModal({
            title: "提示",
            content: "操作权限已被拒绝，请手动前往设置",
            confirmText: "立即设置",
            success: (res) => {
              if (res.confirm) {
                if (plus.os.name === "iOS") {
                  plus.runtime.openURL("app-settings://");
                } else {
                  var Intent = plus.android.importClass(
                    "android.content.Intent"
                  );
                  var Settings = plus.android.importClass(
                    "android.provider.Settings"
                  );
                  var Uri = plus.android.importClass("android.net.Uri");
                  var mainActivity = plus.android.runtimeMainActivity();
                  var intent = new Intent();
                  intent.setAction(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                  );
                  var uri = Uri.fromParts(
                    "package",
                    mainActivity.getPackageName(),
                    null
                  );
                  intent.setData(uri);
                  mainActivity.startActivity(intent);
                }
              }
            },
          });
        },
      });
    },
    ChooseImage4() {
      let _this = this;
      _this.imgList4 = [];
      uni.chooseImage({
        count: 1, //默认1
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        // sourceType: ["album"], //从相册选择
        sourceType: ["camera", "album"],
        success: (res) => {
          var imgFiles = res.tempFilePaths;
          const tempFiles = res.tempFiles;
          let length = "";
          // #ifdef H5
          length = tempFiles[0].name.length;
          let resType = tempFiles[0].name.substring(length - 1, length);
          // #endif
          // #ifndef H5
          length = tempFiles[0].path.length;
          let resType = tempFiles[0].path.substring(length - 1, length);
          // #endif
          if (resType != "g" && resType != "G") {
            uni.showToast({
              title: "不支持当前文件格式",
              icon: "none",
            });
            return;
          }
          if (imgFiles.length > 1) {
            uni.showToast({
              title: "图片最多不能超过1张",
              duration: 2000,
              icon: "none",
            });
            return;
          }
          var uper;
          imgFiles.forEach((el) => {
            uni.showToast({
              title: "正在上传请稍后",
              icon: "none",
              duration: 2000,
            });
            uper = uni.uploadFile({
              // 需要上传的地址
              url:
                "https://www.bangbangtongcheng.com/conven/" +
                "ht/attach/qnUpload",
              // filePath 需要上传的文件
              filePath: el,
              name: "file",
              success(res1) {
                _this.imgList4.push(JSON.parse(res1.data).data[0].url);
              },
            });
          });
          // onProgressUpdate 上传对象更新的方法
          uper.onProgressUpdate(function (res) {});
        },
        fail: (fail) => {
          uni.showModal({
            title: "提示",
            content: "操作权限已被拒绝，请手动前往设置",
            confirmText: "立即设置",
            success: (res) => {
              if (res.confirm) {
                if (plus.os.name === "iOS") {
                  plus.runtime.openURL("app-settings://");
                } else {
                  var Intent = plus.android.importClass(
                    "android.content.Intent"
                  );
                  var Settings = plus.android.importClass(
                    "android.provider.Settings"
                  );
                  var Uri = plus.android.importClass("android.net.Uri");
                  var mainActivity = plus.android.runtimeMainActivity();
                  var intent = new Intent();
                  intent.setAction(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                  );
                  var uri = Uri.fromParts(
                    "package",
                    mainActivity.getPackageName(),
                    null
                  );
                  intent.setData(uri);
                  mainActivity.startActivity(intent);
                }
              }
            },
          });
        },
      });
    },
    ChooseImage9() {
      let _this = this;
      _this.imgList9 = [];
      uni.chooseImage({
        count: 1, //默认1
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        // sourceType: ["album"], //从相册选择
        sourceType: ["camera", "album"],
        success: (res) => {
          var imgFiles = res.tempFilePaths;
          const tempFiles = res.tempFiles;
          let length = "";
          // #ifdef H5
          length = tempFiles[0].name.length;
          let resType = tempFiles[0].name.substring(length - 1, length);
          // #endif
          // #ifndef H5
          length = tempFiles[0].path.length;
          let resType = tempFiles[0].path.substring(length - 1, length);
          // #endif
          if (resType != "g" && resType != "G") {
            uni.showToast({
              title: "不支持当前文件格式",
              icon: "none",
            });
            return;
          }
          if (imgFiles.length > 1) {
            uni.showToast({
              title: "图片最多不能超过1张",
              duration: 2000,
              icon: "none",
            });
            return;
          }
          var uper;
          imgFiles.forEach((el) => {
            uni.showToast({
              title: "正在上传请稍后",
              icon: "none",
              duration: 2000,
            });
            uper = uni.uploadFile({
              // 需要上传的地址
              url:
                "https://www.bangbangtongcheng.com/conven/" +
                "ht/attach/qnUpload",
              // filePath 需要上传的文件
              filePath: el,
              name: "file",
              success(res1) {
                _this.imgList9.push(JSON.parse(res1.data).data[0].url);
              },
            });
          });
          // onProgressUpdate 上传对象更新的方法
          uper.onProgressUpdate(function (res) {});
        },
        fail: (fail) => {
          uni.showModal({
            title: "提示",
            content: "操作权限已被拒绝，请手动前往设置",
            confirmText: "立即设置",
            success: (res) => {
              if (res.confirm) {
                if (plus.os.name === "iOS") {
                  plus.runtime.openURL("app-settings://");
                } else {
                  var Intent = plus.android.importClass(
                    "android.content.Intent"
                  );
                  var Settings = plus.android.importClass(
                    "android.provider.Settings"
                  );
                  var Uri = plus.android.importClass("android.net.Uri");
                  var mainActivity = plus.android.runtimeMainActivity();
                  var intent = new Intent();
                  intent.setAction(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                  );
                  var uri = Uri.fromParts(
                    "package",
                    mainActivity.getPackageName(),
                    null
                  );
                  intent.setData(uri);
                  mainActivity.startActivity(intent);
                }
              }
            },
          });
        },
      });
    },
    ChooseImage10() {
      let _this = this;
      _this.imgList10 = [];
      uni.chooseImage({
        count: 1, //默认1
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        // sourceType: ["album"], //从相册选择
        sourceType: ["camera", "album"],
        success: (res) => {
          var imgFiles = res.tempFilePaths;
          const tempFiles = res.tempFiles;
          let length = "";
          // #ifdef H5
          length = tempFiles[0].name.length;
          let resType = tempFiles[0].name.substring(length - 1, length);
          // #endif
          // #ifndef H5
          length = tempFiles[0].path.length;
          let resType = tempFiles[0].path.substring(length - 1, length);
          // #endif
          if (resType != "g" && resType != "G") {
            uni.showToast({
              title: "不支持当前文件格式",
              icon: "none",
            });
            return;
          }
          if (imgFiles.length > 1) {
            uni.showToast({
              title: "图片最多不能超过1张",
              duration: 2000,
              icon: "none",
            });
            return;
          }
          var uper;
          imgFiles.forEach((el) => {
            uni.showToast({
              title: "正在上传请稍后",
              icon: "none",
              duration: 2000,
            });
            uper = uni.uploadFile({
              // 需要上传的地址
              url:
                "https://www.bangbangtongcheng.com/conven/" +
                "ht/attach/qnUpload",
              // filePath 需要上传的文件
              filePath: el,
              name: "file",
              success(res1) {
                _this.imgList10.push(JSON.parse(res1.data).data[0].url);
              },
            });
          });
          // onProgressUpdate 上传对象更新的方法
          uper.onProgressUpdate(function (res) {});
        },
        fail: (fail) => {
          uni.showModal({
            title: "提示",
            content: "操作权限已被拒绝，请手动前往设置",
            confirmText: "立即设置",
            success: (res) => {
              if (res.confirm) {
                if (plus.os.name === "iOS") {
                  plus.runtime.openURL("app-settings://");
                } else {
                  var Intent = plus.android.importClass(
                    "android.content.Intent"
                  );
                  var Settings = plus.android.importClass(
                    "android.provider.Settings"
                  );
                  var Uri = plus.android.importClass("android.net.Uri");
                  var mainActivity = plus.android.runtimeMainActivity();
                  var intent = new Intent();
                  intent.setAction(
                    Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                  );
                  var uri = Uri.fromParts(
                    "package",
                    mainActivity.getPackageName(),
                    null
                  );
                  intent.setData(uri);
                  mainActivity.startActivity(intent);
                }
              }
            },
          });
        },
      });
    },
    fanhui() {
      uni.navigateBack({
        delta: 1,
      });
    },
    async getLocation() {
      this.getLocation1();
    },
    getLocation1() {
      let _this = this;
      uni.getLocation({
        type: "gcj02",
        highAccuracyExpireTime: "3000",
        success(res) {
          console.log(res);
          _this.latitude = res.latitude;
          _this.longitude = res.longitude;
          // _this.openMap();
        },
        fail(res) {
          console.log(res, "经纬度没有授权");
          uni.setStorageSync("locationState", 0);
          if (uni.getStorageSync("locationState") == 0) {
            uni.showModal({
              title: "提示",
              content: "您已关闭位置权限或获取位置信息失败",
              success: function (res) {
                if (res.confirm) {
                  // plus.runtime.openURL("app-settings:");
                  if (plus.os.name === "iOS") {
                    plus.runtime.openURL("app-settings://");
                  } else {
                    var Intent = plus.android.importClass(
                      "android.content.Intent"
                    );
                    var Settings = plus.android.importClass(
                      "android.provider.Settings"
                    );
                    var Uri = plus.android.importClass("android.net.Uri");
                    var mainActivity = plus.android.runtimeMainActivity();
                    var intent = new Intent();
                    intent.setAction(
                      Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                    );
                    var uri = Uri.fromParts(
                      "package",
                      mainActivity.getPackageName(),
                      null
                    );
                    intent.setData(uri);
                    mainActivity.startActivity(intent);
                  }
                } else if (res.cancel) {
                  console.log("用户点击取消");
                }
              },
            });
            return false;
          }
        },
      });
    },
    openMap() {
      let that = this;
      if (that.latitude == "" || that.longitude == undefined) {
        this.getLocation();
        return;
      } else {
        uni.chooseLocation({
          latitude: that.latitude,
          longitude: that.longitude,
          success: function (res) {
            that.dprzData.officeAddress = res.address;
            that.dprzData.latitude = res.latitude;
            that.dprzData.longitude = res.longitude;
          },
        });
      }
    },
    // 提交
    submit() {
      let that = this;
      if (this.anti_shake) {
        return false;
      }
      let data = {};
      var status = true;
      if (!that.userInfo.id) {
        uni.showToast({
          title: "请先登录",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.storeName) {
        uni.showToast({
          title: "请填写门店名称",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (that.dprzData.storeName.length > 30) {
        uni.showToast({
          title: "门店名称上限为30个字符",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.storeType) {
        uni.showToast({
          title: "请选择门店类型",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.officeArea) {
        uni.showToast({
          title: "请选择办公区域",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.officeAddress) {
        uni.showToast({
          title: "请选择办公地址",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.longitude) {
        uni.showToast({
          title: "请选择办公地址",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.storeContactNumber) {
        uni.showToast({
          title: "请填写门店联系电话",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.legalName) {
        uni.showToast({
          title: "请填写法人姓名",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (!that.dprzData.storeIntroduction) {
        uni.showToast({
          title: "请填写门店介绍",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (that.imgList.length <= 0) {
        uni.showToast({
          title: "请上传门店封面图片",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (that.imgList2.length <= 0) {
        uni.showToast({
          title: "请上传营业执照",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      // if (that.imgList3.length <= 0 && this.shopType!=2) {
      //   uni.showToast({
      //     title: "请上传法人身份证人像面",
      //     icon: "none",
      //     mask: true,
      //   });
      //   status = false;
      //   return false;
      // }
      // if (that.imgList4.length <= 0 && this.shopType!=2) {
      //   uni.showToast({
      //     title: "请上传法人身份证国徽面",
      //     icon: "none",
      //     mask: true,
      //   });
      //   status = false;
      //   return false;
      // }
      if (that.imgList9.length <= 0) {
        uni.showToast({
          title: "请上传个人身份证人像面",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      if (that.imgList10.length <= 0) {
        uni.showToast({
          title: "请上传个人身份证国徽面",
          icon: "none",
          mask: true,
        });
        status = false;
        return false;
      }
      this.dprzData.userId = that.userInfo.id;
      this.dprzData.storeCoverImage = that.imgList[0];
      this.dprzData.businessLicense = that.imgList2[0];
      this.dprzData.legalIdcardJust = that.imgList3[0];
      this.dprzData.legalIdcardBack = that.imgList4[0];
      this.dprzData.personalIdcardJust = that.imgList9[0];
      this.dprzData.personalIdcardBack = that.imgList10[0];
      if (status) {
        this.anti_shake = true;
        this.$myRequest
          .post(
            "/api/mobile/vehicleOwner/authenticationOrModifyDistributor",
            this.dprzData
          )
          .then((res) => {
            if (res.success && res.code == 200) {
              uni.showToast({
                title: "提交成功，等待审核",
                icon: "none",
                mask: true,
              });
              setTimeout(() => {
                this.anti_shake = false;
              }, 500);
              if (that.type) {
                setTimeout(() => {
                  uni.switchTab({
                    url: "/pages/index/index",
                  });
                }, 500);
                return;
              }
              that.init();
            } else {
              uni.showToast({
                title: res.msg,
                icon: "none",
                mask: true,
              });
              that.init();
            }
          });
      }
    },
  },
};
</script>
<style lang="less" scoped>
.tou {
  position: relative;
  width: 100%;
  text-align: center;
  line-height: 88rpx;
  font-size: 36rpx;
  color: #fff;
  background-color: #64b6a8;
  .image1 {
    position: absolute;
    width: 32rpx;
    height: 32rpx;
    // top: 116rpx;
    left: 30rpx;
  }
}
</style>
<style lang="less" scoped>
.box {
  padding-bottom: 140rpx;
  background-color: #fff;
}
.scroll-view {
  /* #ifdef MP  */
  height: calc(100vh - var(--status-bar-height) - 88rpx - 5px - 22px - 144rpx);
  /* #endif */
  /* #ifdef H5 || APP-PULS */
  height: calc(100vh - var(--status-bar-height) - 88rpx - 5px - 144rpx);
  /* #endif */
  /* #ifdef APP */
  height: calc(100vh - var(--status-bar-height) - 88rpx - 5px - 144rpx);
  /* #endif */
}
.tijiao {
  position: fixed;
  width: 100%;
  bottom: 0rpx;
  padding-bottom: 40rpx;
  background-color: #fff;
  z-index: 99;

  checkbox {
    vertical-align: top;
    margin-right: 6rpx;
    margin-left: 40rpx;
  }

  span {
    font-size: 26rpx;
  }

  .but {
    width: 670rpx;
    height: 80rpx;
    background: #64b6a8;
    border-radius: 50rpx;
    font-size: 34rpx;
    text-align: center;
    line-height: 80rpx;
    color: #fff;
    margin-top: 24rpx;
    margin-left: 40rpx;
  }
}

.jieshao {
  background-color: #fff;

  .kuang {
    position: relative;
    width: 670rpx;
    min-height: 80rpx;
    margin-left: 40rpx;
    // padding-bottom: 40rpx;
    background-color: #fff;
    border: 1px solid #c9c9c9;
    .biaoqian {
      height: 40rpx;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      margin-right: 10rpx;
      color: #64b6a8;
    }
    textarea {
      width: 620rpx;
      margin-left: 24rpx;
      margin-top: 14rpx;
      line-height: 50rpx;
      letter-spacing: 2rpx;
    }

    p {
      position: absolute;
      bottom: 20rpx;
      right: 20rpx;
      color: #999999;
    }
  }
}

.cu-form-group uni-picker .picker {
  text-align: left;
}

.cu-form-group .title {
  font-weight: 600;
  font-size: 34rpx;
}

.grid.col-4.grid-square > uni-view {
  width: 212rpx;
  height: 212rpx;
}

/* .sfz {
  .grid.col-4.grid-square > uni-view {
    width: 670rpx;
    height: 360rpx;
    border-radius: 10rpx;
  }
} */
.sfz .id_card {
  width: 670rpx !important;
  height: 360rpx !important;
  border-radius: 10rpx !important;
  padding-bottom: 0px !important;
}

.grid.col-4.grid-square > uni-view:nth-child(3n) {
  margin-right: 0;
}
.fixed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 40;
}
</style>
